import org.junit.Test;

import java.io.PrintStream;
import java.util.function.Consumer;
import java.util.function.Function;

public class ConsumerTest {
    
    @Test
    public void test2() throws Exception {
        Consumer<String> com1 = new Consumer<>() {
            public void accept(String s) {
                System.out.println(s);
            }
        };
        com1.accept("Hello");
    }
    
    @Test
    public void test3() throws Exception {
        Consumer<String> com3 = (s) -> System.out.println(s);
        com3.accept("Hello");
    }

    @Test
    public void test4() throws Exception {
        PrintStream ps = System.out;
        Consumer<String> com4 = System.out::println;
        Consumer<String> com5 = ps::println;
        com4.accept("Hello");
        com5.accept("World");
    }

    @Test
    public void test5() throws Exception {
        Function<Double, Long> f1 = new Function<Double, Long>() {
            @Override
            public Long apply(Double aDouble) {
                return Math.round(aDouble);
            }
        };
        System.out.println(f1.apply(88.88));


        Function<Double, Long> f2 = (n) -> Math.round(n);
        System.out.println(f2.apply(78.88));

        Function<Double, Long> f3 = Math::round;
        System.out.println(f3.apply(58.88));
    }
}
